﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Mbs.Collections;
using System.Diagnostics;

namespace Mbs.Modularity
{
    [DebuggerDisplay("Path={Path}")]
    public class AddInItemAttribute:Attribute
    {
        public IPropertySet Properties { get; private set; }
        public AddInItemAttribute()
        {
            Properties = new PropertySet(StringComparer.InvariantCultureIgnoreCase);
        }

        public string Path
        {
            get { return Properties.Get<string>("Path"); }
            set { Properties.Set("Path", value); }
        }

        public string ParentPath
        {
            get
            {
                var path = Path.TrimEnd('/');
                return path.LastLeftOf('/');
            }
        }

        public string Id
        {
            get
            {
               return Path.TrimEnd('/').LastRightOf('/');
            }
        }

        public int Level
        {
            get { return Path.TrimEnd('/').Split('/').Length; }
        }
    }

    [AttributeUsage(AttributeTargets.Assembly,AllowMultiple=true)]
    [DebuggerDisplay("Path={Path},Label={Label},Command={Command}, Type={Type}")]
    public class SampleAddInItemAttribute : AddInItemAttribute
    {
       
        public string Label
        {
            get { return Properties.Get<string>("Label"); }
            set { Properties.Set("Label", value); }
        }

        public string Type
        {
            get { return Properties.Get<string>("Type"); }
            set { Properties.Set("Type", value); }
        }

        public string Command
        {
            get { return Properties.Get<string>("Command"); }
            set { Properties.Set("Command", value); }
        }
    }
}
